package com.nf.service;

import com.nf.entity.Employee;
import com.nf.mapper.EmpMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class EmpServiceImpl implements EmpService {
    private EmpMapper empMapper=null;
    public Employee test() {
        SqlSession session=null;

        try {
            InputStream inputStream= Resources.getResourceAsStream("mybatis-comfig.xml");
            SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
            session= sqlSessionFactory.openSession();
            empMapper =session.getMapper(EmpMapper.class);
           System.out.println("辣鸡实现类是谁："+empMapper);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

        List<Employee> studentList = empMapper.getAllEmployee();
        for (Employee s:studentList) {
            System.out.println(s.getId()+"  "+s.getUserName());
        }

        //内嵌查询
       /* List<HouseInfo> infos = studentMapper.getAllHouseInfo();
        for (HouseInfo hi:infos) {
            System.out.print(hi.getHid()+"   "+hi.getName()+" "+hi.getTcount()+" "+hi.getKzl());
            System.out.print("(");

            List<Student> students2 = hi.getStudentList();
            for (Student x : students2) {
                System.out.print(x.getName() + ",");
            }
            if (hi.getHid()==1) {

                List<Student> students = studentMapper.findStudentByHouseId(hi.getHid());
                for (Student x : students) {
                    System.out.print(x.getName() + ",");
                }
            }

            System.out.print(")");*/

        return null;
    }
}
